/*
*   Copyright (C) 2011  Jens Kieselbach
*
*   This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You may obtain a copy of the License at http://www.gnu.org/licenses/gpl.html
*/

package de.kieselbach.swing.ui

import java.awt.Color
import java.awt.Dimension
import java.awt.Graphics

import javax.swing.*
import javax.swing.plaf.basic.BasicSplitPaneDivider
import javax.swing.plaf.basic.BasicSplitPaneUI

final class CleanSplitPaneDivider extends BasicSplitPaneDivider {
	
	CleanSplitPaneDivider(BasicSplitPaneUI ui) {
		super(ui)
	}

	@Override
	protected JButton createLeftOneTouchButton() {
		JButton btn = super.createLeftOneTouchButton()
		btn.setOpaque(false)
		return btn
	}

	@Override
	protected JButton createRightOneTouchButton() {
		JButton btn = super.createRightOneTouchButton()
		btn.setOpaque(false)
		return btn
	}

	@Override
	public void paint(Graphics g) {
		if (splitPane.isOpaque()) {
			Color bgColor = getBackground()
			if (bgColor != null) {
				g.setColor(bgColor)
				g.fillRect(0, 0, getWidth(), getHeight())
			}
		}

		if(splitPane.orientation == JSplitPane.VERTICAL_SPLIT) {
			int w = ((width/2) - 5) as int
			int h = (height - 2) as int
			g.color = background.darker()
			g.drawLine(w, 1, w, h)
			g.drawLine(w + 4, 1, w + 4, h)
			g.drawLine(w + 8, 1, w + 8, h)
			
			g.color = background.brighter()
			g.drawLine(w + 1, 1, w + 1, h)
			g.drawLine(w + 5, 1, w + 5, h)
			g.drawLine(w + 9, 1, w + 9, h)
		}
		else {
			int h = ((height/2) - 5) as int
			int w = (width - 2) as int
			g.color = background.darker()
			g.drawLine(1, h, w, h)
			g.drawLine(1, h + 4, w, h + 4)
			g.drawLine(1, h + 8, w, h + 8)
			
			g.color = background.brighter()
			g.drawLine(1, h + 1, w, h + 1)
			g.drawLine(1, h + 5, w, h + 5)
			g.drawLine(1, h + 9, w, h + 9)
		}
	}

	private void paintDragLines(Graphics g) {
		Dimension size = getSize()
		Color bgColor = getBackground()

		if (bgColor != null) {
			g.setColor(bgColor)
			g.fillRect(0, 0, size.@width, size.@height)
		}

		int xCenter = size.width / 2
		int yCenter = size.height / 2
		int y0 = yCenter - 10
		int y1 = yCenter + 10

		Color dark = UIManager.getColor("controlDkShadow")
		int bars = 3

		g.setColor(dark)
		for (int i = 0; i < bars; i++) {
			int x = 2 * i + xCenter - bars
			g.drawLine(x, y0, x, y1)
		}

		super.paint(g)
	}
}